package com.woniuxy.carrental;

import com.woniuxy.carrental.filter.CrossOrignFilter;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement
@MapperScan("com.woniuxy.carrental.mapper")
@SpringBootApplication
public class CarrentalApplication {
    public static void main(String[] args) {

        SpringApplication.run(CarrentalApplication.class, args);
    }

    @Bean
    public FilterRegistrationBean<CrossOrignFilter> filterFilterRegistrationBean(){
        FilterRegistrationBean<CrossOrignFilter> filterFilterRegistrationBean=
                new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new CrossOrignFilter());
        filterFilterRegistrationBean.addUrlPatterns("/*");
        filterFilterRegistrationBean.setOrder(0);
        filterFilterRegistrationBean.setEnabled(true);
        return filterFilterRegistrationBean;
    }

    @Bean
    public static DefaultAdvisorAutoProxyCreator getDefaultAdvisorAutoProxyCreator() {

        DefaultAdvisorAutoProxyCreator defaultAdvisorAutoProxyCreator = new DefaultAdvisorAutoProxyCreator();
        defaultAdvisorAutoProxyCreator.setUsePrefix(true);

        return defaultAdvisorAutoProxyCreator;
    }
}
